package org.ala.tiktools_clickhouse_generator.generator.entity;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.ala.tiktools_clickhouse_generator.config.ConfigInfo;
import org.ala.tiktools_clickhouse_generator.config.ConfigInfo.Author;
import org.ala.tiktools_clickhouse_generator.generator.AbstractInfo;
import org.ala.tiktools_clickhouse_generator.table.TableInfo;
import org.ala.tiktools_clickhouse_generator.tools.NameTools;
import org.ala.tiktools_clickhouse_generator.tools.TimeTools;

/**
 *	Entity信息	
 *
 *	@author ala
 *	@date 2025年6月9日
 */
public class EntityInfo extends AbstractInfo {
	
	
	/**
	 * 	类名，包名，创建时间
	 */
	protected String className, pkg, createTime;
	/**
	 * 	引用
	 */
	protected Set<String> imports;
	/**
	 * 字段列表
	 */
	protected List<FieldInfo> fields;
	

	public EntityInfo(ConfigInfo.Entity e, TableInfo tableInfo, Author author) {
		super(tableInfo, author);
		
		pkg = e.getPkg();
		createTime = TimeTools.formatNow();
		className = NameTools.upFirst(NameTools.hump(tableInfo.getName())) + e.getSuffix();
		fields = tableInfo.getColumns().stream().map(c -> FieldInfo.build(c)).collect(Collectors.toList());
		
		imports = new HashSet<>();
		imports.add("java.io.Serializable");
		fields.forEach(f -> {
			if (!f.isJavaTypeSimple()) {
				imports.add(f.getJavaType().getPackage() + "." + f.getJavaTypeName());
			}
		});
	}
	
	
	public List<FieldInfo> getFields() {
		return fields;
	}
	public void setFields(List<FieldInfo> fields) {
		this.fields = fields;
	}
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}


	public String getPkg() {
		return pkg;
	}


	public void setPkg(String pkg) {
		this.pkg = pkg;
	}


	public String getCreateTime() {
		return createTime;
	}


	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}


	public Set<String> getImports() {
		return imports;
	}


	public void setImports(Set<String> imports) {
		this.imports = imports;
	}
}
